﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MetaModelMemberCollection.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// <summary>
//   Defines the MetaModelMemberCollection type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.ComponentModel.Modelling
{
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;

    public class MetaModelMemberCollection<T> : ReadOnlyCollection<T> where T : MetaModelMember
    {
        #region Fields

        private readonly Dictionary<string, T> _propertyDictionary;

        #endregion

        public MetaModelMemberCollection(IList<T> list) : base(list)
        {
            _propertyDictionary = list.ToDictionary(x => x.Name);
        }

        public T this[string name]
        {
            get { return _propertyDictionary[name]; }
        }

        public T Find(string name)
        {
            T result;
            _propertyDictionary.TryGetValue(name, out result);
            return result;
        }
    }
}